import store from './store'
import {RouterMount,createRouter} from 'uni-simple-router';

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	routes: [...ROUTES]
});

function setAsideBar(to){
	if(store.getters.asideBarOptions.some(el=>el.path === to.path)) {
	getApp().globalData.currentPath = to.path
	store.commit('ASIDE_BAR_OPTION_SET',store.getters.asideBarOptions.map(el=>{
		if(el.path === to.path){
			el.active = true
		}else{
			el.active = false
		}
		return el
	}))
	}
}

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	router.options.routes = []
	next();
});

// 全局路由后置守卫
router.afterEach((to, from) => {
	setAsideBar(to)
    console.log('跳转结束')
})

export {
	router,
	RouterMount
}